

from scipy import stats, integrate
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from scipy.ndimage.filters import gaussian_filter


def myplot(x, y, s, bins=1000):
    heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)
    heatmap = gaussian_filter(heatmap, sigma=s)

    extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
    return heatmap.T, extent



s=32
clim=0.6

# load the coordinates file
x,y = [], []
keyword = 'AX'
color= 'Cy5'

x = np.loadtxt(keyword+'_'+color+'_x.csv', unpack=True)
y = np.loadtxt(keyword+'_'+color+'_y.csv', unpack=True)

x=x*0.30825/1000
y=y*0.30825/1000

fig, ax = plt.subplots()



plt.xlim(0, 1.2)
plt.ylim(0, 1.2)

bins=1000
heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)
heatmap = gaussian_filter(heatmap, sigma=s)

extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
    

plt.imshow(heatmap.T, extent=extent, origin='lower', cmap=cm.jet) 



plt.rcParams.update({'font.size': 32})
#plt.gca().invert_xaxis()
plt.gca().invert_yaxis()
ax.xaxis.tick_top()
plt.axis('off')

plt.clim(0, clim)
cb = plt.colorbar(orientation="horizontal")
cb.set_label('Distribution frequency(a.u.)')



plt.show()


fig = ax.get_figure()

fig.savefig('colorbar_'+color+'_x.png', transparent=True, bbox_inches='tight', pad_inches=0)






